/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 29.07.2005
 *
 *************************************************/
package fightplan.business;

import java.util.List;

import fightplan.business.util.BeltUtil;
import fightplan.business.util.WeightUtil;
import fightplan.business.util.YearUtil;

public class Fighter extends AbstractFighter {
	private static final long serialVersionUID = 1L;

	private String name = "";
	private int year = 1980;
	private Gender gender = Gender.H;
	private int belt = 1; // 1. Dan private int weight = 0; // zu Beginn nicht
							// bekannt.
	private int weight = 0;

	private static int counter = 1;

	public Fighter() {
		setName("Teilnehmer " + (counter++));
	}

	// get / set

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public String getWeightFormatted() {
		return WeightUtil.format(weight);
	}

	public void setWeightFormatted(String s) {
		weight = WeightUtil.parse(s);
	}

	public String getName() {
		return name;
	}

	@Override
	public String getDisplayName() {
		if (getDojo() == null || getDojo().getName() == null || getDojo().getName().trim().length() == 0) {
			return getName();
		} else {
			return getName() + " (" + getDojo().getName() + ")";
		}
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public String getYearFormatted() {
		return YearUtil.format(year);
	}

	public void setYearFormatted(String s) {
		year = YearUtil.parse(s);
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public int getBelt() {
		return belt;
	}

	public void setBelt(int belt) {
		this.belt = belt;
	}

	public String getBeltFormatted() {
		return BeltUtil.format(belt);
	}

	public void setBeltFormatted(String s) {
		belt = BeltUtil.parse(s);
	}

	public String getCategoryNames(Tournament tournament) {
		String names = "";
		List<Category> categories = searchCategories(tournament);
		for (int i = 0; i < categories.size(); i++) {
			Category category = categories.get(i);

			names += category.getNameOrDescription();
			if (i < categories.size() - 1) {
				names += " / ";
			}
		}
		return names;
	}

}
